package cn.lookup.service.impl;

import cn.lookup.dao.UserDao;
import cn.lookup.domain.User;
import cn.lookup.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service("userService")
public class UserServiceImpl implements UserService {
    @Autowired
    @Qualifier("userDao")
    private UserDao userDao;
    public List<User> getUserList() {
        List<User> userList = userDao.getUserList();
        return userList;
    }
    @Transactional
    public void submitAdd(User user, Long[] roleIds) {
        Long userId = userDao.submitAdd(user);
        for (Long roleId : roleIds) {
            userDao.submitRoleAndUserRelations(roleId,userId);
        }
    }
    //删除用户
    @Transactional
    public void delete(Long userId) {
        userDao.deleteRoleAndUserRelationship(userId);
        userDao.deleteUserById(userId);
    }
}
